Skip to content

getBlockData(Class) & hasOneDurabilityLeft() utils#871

Open
JustAHuman-xD wants to merge 3 commits into
masterfrom
human/pylon-polish-pass
Open

getBlockData(Class) & hasOneDurabilityLeft() utils#871
JustAHuman-xD wants to merge 3 commits into
masterfrom
human/pylon-polish-pass

Conversation

@JustAHuman-xD

Copy link
Copy Markdown
Contributor

for the pylon polish pass

@JustAHuman-xD JustAHuman-xD changed the title getBlockData(Class) util getBlockData(Class) & hasOneDurabilityLeft() utils Jul 8, 2026
fun ItemStack.hasOneDurabilityLeft(): Boolean {
val maxDamage = getData(DataComponentTypes.MAX_DAMAGE) ?: return false
val damage = getData(DataComponentTypes.DAMAGE) ?: return false
return damage == maxDamage - 1 && !hasData(DataComponentTypes.UNBREAKABLE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: move the unbreakable check up to the top as a guard clause.


fun getBlockData() = getBlockData(BlockData::class.java)

fun <D : BlockData> getBlockData(dataType: Class<D>) = block.getBlockData(dataType)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reified version for kotlin users?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants